package com.igeek.boot.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author fengqq
 * @Description 自定义Servlet
 * @Date 2024/8/19  15:39
 *
 * 自定义Servlet的注册：
 *  1.自定义类  extends HttpServlet 重写 doGet/doPost方法
 *  2.在类上面 添加 注解 @WebServlet(name = "servlet名称",urlPatterns = 映射处理请求的路径)
 *  3.在主启动类上 添加 @ServletComponentScan(basePackages = "com.igeek.boot.servlet")
 *  注意：servlet中 请求路径必须以 / 斜杠开头，不然会导致tomcat启动失败
 *
 *  测试：发起 /my 请求 最终该请求由DispatcherServlet 还是 MyServlet？？？
 *          DispatcherServlet 映射路径 /**
 *          MyServlet         映射路径 /my
 *          如果映射路径可以精确匹配到Servlet 则直接由自定义的MyServlet来进行处理,不会经过后续的拦截器interceptor
 */
//@WebServlet(name = "myServlet",urlPatterns = {"/my","/one"})
public class MyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("MyServlet执行doGet方法...");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("MyServlet执行doPost方法...");
    }
}
